package map;

import java.util.HashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class HashMapBugTest {

    private static HashMap map = new HashMap();

    public static void test() {

        ExecutorService serivce = Executors.newFixedThreadPool(10);
        int count = 10;
        int max = 10000000;
        for(int j = 0; j < count/2; j++){
            final int index = j;
            serivce.execute(() -> {
                for (int i = 0; i < max; i++) {
                    map.put(new Integer(i), i);
                }
                System.out.println("t" + index + " over");
            });
        }

        for(int j = 0; j < count/2; j++){
            final int index = j;
            serivce.execute(() -> {
                for (int i = 0; i < max; i++) {
                    map.get(new Integer(i));
                }
                System.out.println("t" + (index+5) + " over");
            });
        }
        serivce.shutdown();
        System.out.println("执行完毕");
    }

    public static void main(String[] args) {
        test();
        System.out.println("size:" + map.size());
    }
}
